<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
    <!--	<title>批量反地址解析+商圈</title>-->
    <style type="text/css">
        body, html {
            width: 100%;
            height: 100%;
            margin: 0;
            font-family: "微软雅黑";
        }

        #l-map {
            height: 80%;
            width: 100%;
        }

        #r-result {
            width: 100%;
            font-size: 14px;
            line-height: 20px;
        }
    </style>
	<script type="text/javascript"
			src="http://api.map.baidu.com/api?v=3.0&ak=bpgN00yqoZ7w4onqvwOF4oG510Wo2dBP">
	</script>
    <script src="../js/jquery.min.js"></script>
</head>
<body onload="init()">
<div id="l-map"></div>
<!--<div id="r-result">
	<input type="button" value="批量反地址解析+商圈" onclick="bdGEO(0)" />
	<div id="result"></div>
</div>-->
</body>
</html>
<script type="text/javascript">

    // 百度地图API功能
    var map = new BMap.Map("l-map");
    /*var point = new BMap.Point(116.331398,39.897445);
    map.centerAndZoom(point,10);*/
    map.centerAndZoom("深圳市", 11);

    //根据浏览器定位当前位置
    function init() {
        /*var geolocation = new BMap.Geolocation();
        geolocation.getCurrentPosition(function(r){
            if(this.getStatus() == BMAP_STATUS_SUCCESS){
                var mk = new BMap.Marker(r.point);
                // map.addOverlay(mk);
                map.panTo(r.point);
                // alert('您的位置：'+r.point.lng+','+r.point.lat);
            }
            else {
                // alert('failed'+this.getStatus());
            }
        });*/
        load();
    }

    //加载分店位置
    function load() {
        map.enableScrollWheelZoom(true);
        var index = 0;
        var myGeo = new BMap.Geocoder();
        var adds = [];
        // new BMap.Point(114.43111595784,30.483957430496)
        var addNames = [];
        $.ajax({
            type: "GET",
            url: "/address/findAllMaps.do",
            // data:JSON.stringify(userList),
            async: false,
            contentType: "application/json;charset=utf-8",
            success: function (data) {
                for (var x = 0; x < data.length; x++) {
                    adds.push(new BMap.Point(data[x].lng, data[x].lat));
                    addNames.push(data[x].addressName);
                }
            }
        });

        // adds=[new BMap.Point(114.43111595784,30.483957430496)];
        for (var i = 0; i < adds.length; i++) {
            var marker = new BMap.Marker(adds[i]);
            map.addOverlay(marker);
            marker.setLabel(new BMap.Label(addNames[i], {offset: new BMap.Size(20, -10)}));
        }

        function bdGEO() {
            var pt = adds[index];
            geocodeSearch(pt);
            index++;
        }

        function geocodeSearch(pt) {
            if (index < adds.length - 1) {
                setTimeout(window.bdGEO, 400);
            }
            myGeo.getLocation(pt, function (rs) {
                var addComp = rs.addressComponents;
                document.getElementById("result").innerHTML += index + ". " + adds[index - 1].lng + "," + adds[index - 1].lat + "：" + "商圈(" + rs.business + ")  结构化数据(" + addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber + ")<br/><br/>";
            });
        }
    }

</script>
